import Vue from 'vue'
import Vuex from 'vuex'
import http from "@/request"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 0,
    todoList: [
      { id: 1, active: true },
      { id: 2, active: true },
      { id: 3, active: false },
    ],
    menu: null,
  },
  getters: {
    // (state, getters)
    todoListCount: (state) => {
      return state.todoList.filter(v => v.active).length
    },
    getTodoById: (state) => (id) => {
      return state.todoList.find(v => v.id === id)
    }  
  },
  mutations: {
    add(state){
      state.count++
    },
    "GET_USER_MENU": (state, payload) => {
      state.menu = payload
    }
  },
  actions: {
    'GET_USER_MENU': ({commit}) => {
      http.get("/admin/base/auth/menus/left").then(res => {
        console.log("menu res ==> ", res)
        commit('GET_USER_MENU', res)
      }).catch(err => {
        console.log("menu err ==> ", err)
      })
    }
  }
})
